#include <iostream>
using namespace std;

int min(int a, int b, int c) {
	return ((a<b?a:b)<c)?(a<b?a:b):c;
}

int get_ugly(int index) {
	int* ugly_number = new int[index];
	ugly_number[0] = 1;
	int next_ugly = 1;

	int *p2 = ugly_number;
	int *p3 = ugly_number;
	int *p5 = ugly_number;

	while (next_ugly < index) {
		int next = min(*p2*2, *p3*3, *p5*5);
		ugly_number[next_ugly] = next;

		while (*p2*2 <= ugly_number[next_ugly])
			p2++;		
		while (*p3*3 <= ugly_number[next_ugly])
			p3++;		
		while (*p5*5 <= ugly_number[next_ugly])
			p5++;

		next_ugly++;
	}

	int ugly = ugly_number[next_ugly-1];
	delete [] ugly_number;
	return ugly;
}

//int main() {
//	int ret = get_ugly(1500);
//
//	return 0;
//}